// vue.config.js
/**
 * @type {import('@vue/cli-service').ProjectOptions}
 */
require('shelljs/global');
const path = require('path');
const fs = require('fs');
const express = require('express');
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// vue.config.js
module.exports = {
  productionSourceMap: false,
  outputDir: '../plugin/resume',
  css: {
    extract: {
      filename: 'css/bundle.css'
    }
  },
  pages: {
    index: {
      entry: 'src/main.js',
      template: 'index.html' // 模板来源
    }
  },
  chainWebpack: (config) => {
    // 移除eslint插件
    config.plugins.delete('eslint');
  },
  publicPath: './',
  configureWebpack: {
    output: {
      filename: 'js/bundle.js' // 输出文件的名称
    },
    resolve: {
      //extensions: ['.css', '.js', '.vue'], //请求本地json
      alias: {
        '@': path.resolve(__dirname, './src'),
        '@s': path.resolve(__dirname, './src/static'),
        '@c': path.resolve(__dirname, './src/components'),
        static: path.resolve(__dirname, './src/static'),
        service: path.resolve(__dirname, './src/service')
      } // 别名配置
    },
    optimization: {
      splitChunks: {
        cacheGroups: {
          default: false, // 关闭默认的分割策略
          vendors: false, // 关闭默认的vendors分割策略
          commons: {
            // 添加一个新的commons分割策略
            name: 'commons',
            chunks: 'all',
            minChunks: 2,
            minSize: 0
          }
        }
      }
    },
    plugins: [
      // 使用webpack的SplitChunksPlugin插件来分割入口chunk中共同的部分
      new webpack.optimize.SplitChunksPlugin({
        name: 'commons',
        minChunks: function (module, count) {
          // 对于npm包，只在imported两次以上的情况下进行分割
          return module.resource && module.resource.includes('node_modules') && count >= 2;
        }
      })
    ]
  }
};
